/**
 * @author haixuanwo
 * @email haixuanwo_clark@hotmail.com
 * @date 2021-01-23
 * @brief libevent 封装类
 */

#ifndef MY_LIBEVENT_H
#define MY_LIBEVENT_H

extern "C" {
#include <event2/event.h>
#include <event2/event_struct.h>
#include <event2/util.h>
#include <event2/event-config.h>
#include <event2/bufferevent.h>
#include <event2/buffer.h>
#include <event2/listener.h>
#include <event2/util.h>
}

class MyLibevent
{
public:
	MyLibevent();

	static void timeout_cb(evutil_socket_t fd, short event, void *arg);
	int timer_test();

	
	static void listener_cb(struct evconnlistener *listener, evutil_socket_t fd,
			struct sockaddr *sa, int socklen, void *user_data);
	
	static void signal_cb(evutil_socket_t sig, short events, void *user_data);	
	static void conn_writecb(struct bufferevent *bev, void *user_data); 
	static void conn_eventcb(struct bufferevent *bev, short events, void *user_data);

	int my_event_base_dispatch();

	~MyLibevent();

private:
	struct timeval tv;
	struct event timeout;
	struct event_base *eventBase;
	struct event *signal_event;
	struct evconnlistener *listener;
};

#endif

